import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import type { OutputOptions } from 'rollup'

export default defineConfig({
  plugins: [vue()],
  publicDir: false,
  build: {
    target: 'modules',
    //打包文件目录
    outDir: 'dist',
    //压缩
    minify: true,
    //css分离
    cssCodeSplit: false,
    // rbga色值禁止转成十六进制
    cssTarget: 'chrome61',
    lib: {
      entry: './index.ts',
      // formats: ['es', 'cjs'],
      name: 'svmp',
      fileName: 'svmp',
    },
    rollupOptions: {
      // 排除打包的库
      external: ['vue', 'element-plus', '@element-plus/icons-vue'],
      input: ['./index.ts'],
      output: ['esm', 'cjs'].map((format) => ({
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        name: 'svmp',
        format,
        dir: 'dist',
        entryFileNames: `svmp.[format].js`,
        assetFileNames: 'index.css',
        preserveModulesRoot: 'src',
      })) as OutputOptions[],
    },
  },
})
